package com.zte.claa.inficombo.csa.app.service.rescmd.parsers;

import com.zte.claa.inficombo.csa.app.service.rescmd.ResDevCmdParserDefault;
import com.zte.claa.inficombo.csa.app.util.JsonUtils;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

public class HuaXiaRmResDevCmdParser extends ResDevCmdParserDefault{
	public static final String MSG_TYPE = "rs_huaxia_plate_recog";
		
	@Override
	public String getDevType() {
		return MSG_TYPE;
	}
	
	@Override
	public Object dealResDevCmdFunc(String appEui, String devEui, boolean confirm, int port, String payload, Map<String, Object> extParaMap) throws Exception{
		logger.info("dealResDevCmdFunc devtype:"+ MSG_TYPE + ",devEui:" + devEui + ",payload:" + payload);
		JSONObject json = new JSONObject(payload);
		String cmdCode = JsonUtils.getJsonAttrVal(json, "cmd", null);
		if(cmdCode == null){
			logger.error("[*@@*]Can not get cmd code from payload[cmd]: "+payload);
			throw new Exception("Can not get cmd code from payload[cmd]: "+payload);
		}
		Map<String, Object> cmdParaMap = null;
		JSONObject jsonParaObj = JsonUtils.getSubObject(json, "paras");
		if(jsonParaObj == null){
			cmdParaMap = new HashMap<String, Object>(0);
		} else {
			cmdParaMap = JsonUtils.jsonStrToHashMap(jsonParaObj.toString());
		}
		if(cmdCode.equals("gpio_data")){
			this.container.getHuaXiaService().cacheHuaXiaCmd_Gpio_Data(devEui, cmdParaMap);
		}else if(cmdCode.equals("rs485_data")){
			this.container.getHuaXiaService().cacheHuaXiaCmd_Rs485_Data(devEui, cmdParaMap);
		}else if(cmdCode.equals("triger_data")){
			this.container.getHuaXiaService().cacheHuaXiaCmd_Triger_Data(devEui, cmdParaMap);
		}else if(cmdCode.equals("whitelist_data")){
			this.container.getHuaXiaService().cacheHuaXiaCmd_Whitelist_Data(devEui, cmdParaMap);
		}		
		return null;	
	}	
	
}

